home *** CD-ROM | disk | FTP | other *** search
/ SGI Freeware 1999 August / SGI Freeware 1999 August.iso / dist / fw_xemacs.idb / usr / freeware / lib / xemacs-20.4 / lisp / w3 / url-ns.el.z / url-ns.el
Encoding:
Text File  |  1998-05-21  |  3.4 KB  |  107 lines

  1. ;;; url-ns.el --- Various netscape-ish functions for proxy definitions
  2. ;; Author: wmperry
  3. ;; Created: 1997/10/03 15:19:07
  4. ;; Version: 1.6
  5. ;; Keywords: comm, data, processes, hypermedia
  6.  
  7. ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
  8. ;;; Copyright (c) 1997 Free Software Foundation, Inc.
  9. ;;;
  10. ;;; This file is not part of GNU Emacs, but the same permissions apply.
  11. ;;;
  12. ;;; GNU Emacs is free software; you can redistribute it and/or modify
  13. ;;; it under the terms of the GNU General Public License as published by
  14. ;;; the Free Software Foundation; either version 2, or (at your option)
  15. ;;; any later version.
  16. ;;;
  17. ;;; GNU Emacs is distributed in the hope that it will be useful,
  18. ;;; but WITHOUT ANY WARRANTY; without even the implied warranty of
  19. ;;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  20. ;;; GNU General Public License for more details.
  21. ;;;
  22. ;;; You should have received a copy of the GNU General Public License
  23. ;;; along with GNU Emacs; see the file COPYING.  If not, write to the
  24. ;;; Free Software Foundation, Inc., 59 Temple Place - Suite 330,
  25. ;;; Boston, MA 02111-1307, USA.
  26. ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
  27.  
  28. (require 'url-gw)
  29.  
  30. ;;;###autoload
  31. (defun isPlainHostName (host)
  32.   (not (string-match "\\." host)))
  33.  
  34. ;;;###autoload
  35. (defun dnsDomainIs (host dom)
  36.   (string-match (concat (regexp-quote dom) "$") host))
  37.  
  38. ;;;###autoload
  39. (defun dnsResolve (host)
  40.   (url-gateway-nslookup-host host))
  41.  
  42. ;;;###autoload
  43. (defun isResolvable (host)
  44.   (if (string-match "^[0-9.]+$" host)
  45.       t
  46.     (not (string= host (url-gateway-nslookup-host host)))))
  47.  
  48. ;;;###autoload
  49. (defun isInNet (ip net mask)
  50.   (let ((netc (split-string ip "\\."))
  51.     (ipc  (split-string net "\\."))
  52.     (maskc (split-string mask "\\.")))
  53.     (if (or (/= (length netc) (length ipc))
  54.         (/= (length ipc) (length maskc)))
  55.     nil
  56.       (setq netc (mapcar 'string-to-int netc)
  57.         ipc (mapcar 'string-to-int ipc)
  58.         maskc (mapcar 'string-to-int maskc))
  59.       (and
  60.        (= (logand (nth 0 netc) (nth 0 maskc))
  61.       (logand (nth 0 ipc)  (nth 0 maskc)))
  62.        (= (logand (nth 1 netc) (nth 1 maskc))
  63.       (logand (nth 1 ipc)  (nth 1 maskc)))
  64.        (= (logand (nth 2 netc) (nth 2 maskc))
  65.       (logand (nth 2 ipc)  (nth 2 maskc)))
  66.        (= (logand (nth 3 netc) (nth 3 maskc))
  67.       (logand (nth 3 ipc)  (nth 3 maskc)))))))
  68.  
  69. ;; Netscape configuration file parsing
  70. (defvar url-ns-user-prefs nil
  71.   "Internal, do not use.")
  72.  
  73. ;;;###autoload
  74. (defun url-ns-prefs (&optional file)
  75.   (if (not file)
  76.       (setq file (expand-file-name "~/.netscape/preferences.js")))
  77.   (if (not (and (file-exists-p file)
  78.         (file-readable-p file)))
  79.       (message "Could not open %s for reading" file)
  80.     (save-excursion
  81.       (let ((false nil)
  82.         (true t))
  83.     (setq url-ns-user-prefs (make-hash-table :size 13 :test 'equal))
  84.     (set-buffer (get-buffer-create " *ns-parse*"))
  85.     (erase-buffer)
  86.     (insert-file-contents file)
  87.     (goto-char (point-min))
  88.     (while (re-search-forward "^//" nil t)
  89.       (replace-match ";;"))
  90.     (goto-char (point-min))
  91.     (while (re-search-forward "^user_pref(" nil t)
  92.       (replace-match "(url-ns-set-user-pref "))
  93.     (goto-char (point-min))
  94.     (while (re-search-forward "\"," nil t)
  95.       (replace-match "\""))
  96.     (goto-char (point-min))
  97.     (eval-buffer)))))
  98.  
  99. (defun url-ns-set-user-pref (key val)
  100.   (cl-puthash key val url-ns-user-prefs))
  101.  
  102. ;;;###autoload
  103. (defun url-ns-user-pref (key &optional default)
  104.   (cl-gethash key url-ns-user-prefs default))
  105.  
  106. (provide 'url-ns)
  107.